/**
 * 
 */
package ru.athena.runTool;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;

/**
 * @author corc_usr
 *
 */
public class AppProperties extends Properties {
	private static final String CONNECTION_STRING = "connectionString";
	private static final String FILE_PATH = "lastFile";
	private static final String USER_NAME = "userName";	
	/**
	 * 
	 */
	private static final long serialVersionUID = 4219934836759820234L;
	private static final String PROPERTIES_FILE_NAME = "RunTool.properties";
	/**
	 * 
	 */
	public String getFilePath() {
		return getProperty( FILE_PATH ); 
	}
	
	public void setFilePath( String path) {
		setProperty(FILE_PATH, path);
	}
	
	public String getConnectionString() {
		return getProperty(CONNECTION_STRING);
	}
	
	public void setConnectionString( String value) {
		setProperty( CONNECTION_STRING,	value);
	}

	public String getUserName() {
		return getProperty(USER_NAME);
	}
	
	public void setUserName( String value) {
		setProperty( USER_NAME,	value);
	}

	public AppProperties() {
		super();
		try {
			InputStream propFile = new FileInputStream(PROPERTIES_FILE_NAME);
			this.loadFromXML(propFile);
		} catch (FileNotFoundException e) {
			//e.printStackTrace();
		} catch (IOException e) {
			//e.printStackTrace();
		}		
	}

	@Override
	public synchronized Object setProperty(String key, String value) {
		try {
			OutputStream propFile = new FileOutputStream(PROPERTIES_FILE_NAME);			
			this.storeToXML(propFile, "");
		} catch (IOException e) {
			//e.printStackTrace();
		}
		return super.setProperty(key, value);
	}

	public String getCharset() {
		return "windows-1251";
	}
	
}
